<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>demo_emgmm.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_name>demo_emgmm</span>(<span class=defun_in>action,hfigure,varargin</span>)<br>
<span class=h1>%&nbsp;DEMO_EMGMM&nbsp;Demo&nbsp;on&nbsp;Expectation-Maximization&nbsp;(EM)&nbsp;algorithm.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;demo_emgmm</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;demo&nbsp;shows&nbsp;the&nbsp;Expectation-Maximization&nbsp;(EM)&nbsp;algorithm</span><br>
<span class=help>%&nbsp;&nbsp;[Schles68][DLR77]&nbsp;for&nbsp;Gaussians&nbsp;mixture&nbsp;model&nbsp;(GMM).&nbsp;The&nbsp;EM&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;fits&nbsp;the&nbsp;GMM&nbsp;to&nbsp;i.i.d.&nbsp;sample&nbsp;data&nbsp;(in&nbsp;this&nbsp;case&nbsp;only&nbsp;2D)&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;such&nbsp;that&nbsp;the&nbsp;likelihood&nbsp;is&nbsp;maximized.&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;The&nbsp;found&nbsp;model&nbsp;is&nbsp;described&nbsp;by&nbsp;ellipsoids&nbsp;(shape&nbsp;of&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;covariances)&nbsp;and&nbsp;a&nbsp;crosses&nbsp;(mean&nbsp;value&nbsp;vectors).&nbsp;The&nbsp;value</span><br>
<span class=help>%&nbsp;&nbsp;of&nbsp;the&nbsp;optimized&nbsp;log-likelihood&nbsp;function&nbsp;for&nbsp;the&nbsp;current&nbsp;estimate&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;is&nbsp;displayed&nbsp;in&nbsp;the&nbsp;bottom&nbsp;part.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Control:</span></span><br>
<span class=help>%&nbsp;&nbsp;Covariance&nbsp;&nbsp;-&nbsp;Determines&nbsp;type&nbsp;of&nbsp;the&nbsp;covariance&nbsp;matrix:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Diagonal&nbsp;(independent&nbsp;features),</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Full&nbsp;(correlated&nbsp;features).</span><br>
<span class=help>%&nbsp;&nbsp;Components&nbsp;&nbsp;-&nbsp;Number&nbsp;of&nbsp;components&nbsp;(Gaussians)&nbsp;in&nbsp;the&nbsp;mixture.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;Iterations&nbsp;&nbsp;-&nbsp;Number&nbsp;of&nbsp;iterations&nbsp;in&nbsp;one&nbsp;step.</span><br>
<span class=help>%&nbsp;&nbsp;Random&nbsp;init&nbsp;-&nbsp;the&nbsp;initial&nbsp;model&nbsp;is&nbsp;randomly&nbsp;generated&nbsp;and/or&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first&nbsp;n&nbsp;training&nbsp;samples&nbsp;are&nbsp;taken&nbsp;as&nbsp;the</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mean&nbsp;vectors.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;FIG2EPS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Export&nbsp;screen&nbsp;to&nbsp;the&nbsp;PostScript&nbsp;file.</span><br>
<span class=help>%&nbsp;&nbsp;Save&nbsp;model&nbsp;&nbsp;-&nbsp;Save&nbsp;current&nbsp;model&nbsp;to&nbsp;file.</span><br>
<span class=help>%&nbsp;&nbsp;Load&nbsp;data&nbsp;&nbsp;&nbsp;-&nbsp;Load&nbsp;input&nbsp;point&nbsp;sets&nbsp;from&nbsp;file.</span><br>
<span class=help>%&nbsp;&nbsp;Create&nbsp;data&nbsp;-&nbsp;Invoke&nbsp;program&nbsp;for&nbsp;creating&nbsp;point&nbsp;sets.</span><br>
<span class=help>%&nbsp;&nbsp;Reset&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Set&nbsp;the&nbsp;tested&nbsp;algorithm&nbsp;to&nbsp;the&nbsp;initial&nbsp;state.</span><br>
<span class=help>%&nbsp;&nbsp;Play&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Run&nbsp;the&nbsp;tested&nbsp;algorithm.</span><br>
<span class=help>%&nbsp;&nbsp;Stop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Stop&nbsp;the&nbsp;running&nbsp;algorithm.</span><br>
<span class=help>%&nbsp;&nbsp;Step&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Perform&nbsp;only&nbsp;one&nbsp;step.</span><br>
<span class=help>%&nbsp;&nbsp;Info&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Info&nbsp;box.</span><br>
<span class=help>%&nbsp;&nbsp;Close&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Close&nbsp;the&nbsp;program.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;EMGMM.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;19-sep-2003,&nbsp;VF</span><br>
<span class=help1>%&nbsp;11-june-2001,&nbsp;V.Franc,&nbsp;comments&nbsp;added.</span><br>
<span class=help1>%&nbsp;27.02.00&nbsp;V.&nbsp;Franc</span><br>
<span class=help1>%&nbsp;&nbsp;5.&nbsp;4.00&nbsp;V.&nbsp;Franc</span><br>
<span class=help1>%&nbsp;23.06.00&nbsp;V.&nbsp;Hlavac&nbsp;Comments&nbsp;polished.&nbsp;Message&nbsp;when&nbsp;no&nbsp;data&nbsp;loaded.</span><br>
<span class=help1>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Export&nbsp;of&nbsp;the&nbsp;solution&nbsp;to&nbsp;global&nbsp;variables.</span><br>
<span class=help1>%&nbsp;27-mar-2001,&nbsp;V.Franc,&nbsp;Graph&nbsp;og&nbsp;log-likelihood&nbsp;function&nbsp;added</span><br>
<br>
<br>
<hr>
<span class=comment>%&nbsp;Used&nbsp;functions:&nbsp;PPOINTS,&nbsp;PNMIX</span><br>
<br>
<span class=comment>%&nbsp;==&nbsp;Global&nbsp;variables,&nbsp;used&nbsp;to&nbsp;export&nbsp;results&nbsp;from&nbsp;demo_emgmm&nbsp;========</span><br>
<br>
<span class=type>global</span>&nbsp;UNSU_MI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;K&nbsp;vectors&nbsp;with&nbsp;mean&nbsp;values</span><br>
<span class=type>global</span>&nbsp;UNSU_SIGMA&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;K&nbsp;covariance&nbsp;matrices</span><br>
<span class=type>global</span>&nbsp;UNSU_PK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;K&nbsp;apriori&nbsp;probabilities&nbsp;for&nbsp;each&nbsp;distributions.</span><br>
<span class=comment>%global&nbsp;UNSU_eI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&nbsp;Used&nbsp;only&nbsp;by&nbsp;the&nbsp;next&nbsp;iteration,&nbsp;not&nbsp;globalised</span><br>
<span class=type>global</span>&nbsp;UNSU_solution&nbsp;<span class=comment>%&nbsp;1&nbsp;if&nbsp;alg.&nbsp;finished&nbsp;in&nbsp;stationary&nbsp;point,&nbsp;0&nbsp;otherwise</span><br>
<span class=type>global</span>&nbsp;UNSU_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Number&nbsp;of&nbsp;iterations&nbsp;the&nbsp;algorithm&nbsp;performed</span><br>
<br>
<span class=comment>%&nbsp;==&nbsp;Constants&nbsp;=====================================================</span><br>
<br>
AXIST_ADD=10;<br>
AXISY_ADD=5;<br>
<br>
BORDER=0.25;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;space&nbsp;betwean&nbsp;window&nbsp;outer&nbsp;and&nbsp;the&nbsp;points</span><br>
CENTERSIZE=10;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;size&nbsp;of&nbsp;center&nbsp;point</span><br>
LINE_WIDTH=1;<br>
AXIST_ADD=10;<br>
DATA_IDENT=<span class=quotes>'Finite&nbsp;sets,&nbsp;enumeration'</span>;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;file&nbsp;identifier</span><br>
randinit=1;<br>
<br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;1,<br>
&nbsp;&nbsp;&nbsp;action&nbsp;=&nbsp;<span class=quotes>'initialize'</span>;<br>
<span class=keyword>end</span><br>
<br>
<span class=comment>%&nbsp;What&nbsp;action&nbsp;is&nbsp;required&nbsp;?</span><br>
<span class=keyword>switch</span>&nbsp;lower(action)<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'initialize'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Initialize&nbsp;user&nbsp;interface&nbsp;control&nbsp;and&nbsp;figure&nbsp;window&nbsp;================</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Figure</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;=============================================================</span><br>
&nbsp;&nbsp;&nbsp;left=0.2;<br>
&nbsp;&nbsp;&nbsp;width=0.6;<br>
&nbsp;&nbsp;&nbsp;bottom=0.1;<br>
&nbsp;&nbsp;&nbsp;height=0.8;<br>
&nbsp;&nbsp;&nbsp;hfigure=<span class=graph>figure</span>(<span class=quotes>'Name'</span>,<span class=quotes>'EM&nbsp;algorithm'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Visible'</span>,<span class=quotes>'off'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'NumberTitle'</span>,<span class=quotes>'off'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'tag'</span>,<span class=quotes>'demo_emgmm'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'doublebuffer'</span>,<span class=quotes>'on'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'backingstore'</span>,<span class=quotes>'off'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Axes&nbsp;===============================================================</span><br>
&nbsp;&nbsp;&nbsp;left=0.1;<br>
&nbsp;&nbsp;&nbsp;width=0.65;<br>
&nbsp;&nbsp;&nbsp;bottom=0.45;<br>
&nbsp;&nbsp;&nbsp;height=0.5;<br>
&nbsp;&nbsp;&nbsp;haxes1=<span class=graph>axes</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'NextPlot'</span>,<span class=quotes>'add'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'UserData'</span>,[],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height]);<br>
&nbsp;&nbsp;&nbsp;xlabel(<span class=quotes>'feature&nbsp;x\_1'</span>);<br>
&nbsp;&nbsp;&nbsp;ylabel(<span class=quotes>'feature&nbsp;x\_2'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;htitle1=title(<span class=quotes>'No&nbsp;data&nbsp;loaded'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'VerticalAlignment'</span>,<span class=quotes>'bottom'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Parent'</span>,haxes1,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'HorizontalAlignment'</span>,<span class=quotes>'left'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[0&nbsp;1&nbsp;0]);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;axes&nbsp;log-Likelihood&nbsp;graph</span><br>
&nbsp;&nbsp;&nbsp;left=0.1;<br>
&nbsp;&nbsp;&nbsp;width=0.65;<br>
&nbsp;&nbsp;&nbsp;bottom=0.1;<br>
&nbsp;&nbsp;&nbsp;height=0.25;<br>
&nbsp;&nbsp;&nbsp;haxes2=<span class=graph>axes</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'NextPlot'</span>,<span class=quotes>'add'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height]);<br>
&nbsp;&nbsp;&nbsp;ylabel(<span class=quotes>'logL(t)'</span>);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;htitle2=title(<span class=quotes>'Log-likelihood&nbsp;function'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Parent'</span>,haxes2,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'VerticalAlignment'</span>,<span class=quotes>'bottom'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'HorizontalAlignment'</span>,<span class=quotes>'left'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[0&nbsp;1&nbsp;0]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;htxsteps=xlabel(<span class=quotes>'step&nbsp;number&nbsp;t=0'</span>);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Comment&nbsp;Window&nbsp;frame&nbsp;==============================================</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;bottom=0.05;</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;height=0.16;</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;uicontrol(&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Style','frame',&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Units','normalized',&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Position',[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'BackgroundColor',[0.5&nbsp;0.5&nbsp;0.5]);</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Text&nbsp;label</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;uicontrol(&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Style','text',&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Units','normalized',&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Position',[left&nbsp;height-0.01&nbsp;width&nbsp;0.05],&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'BackgroundColor',[0.5&nbsp;0.5&nbsp;0.5],&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ForegroundColor',[1&nbsp;1&nbsp;1],&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'String','Comment&nbsp;Window');</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Edit&nbsp;window</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;border=0.01;</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;hconsole=uicontrol(&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Style','edit',&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'HorizontalAlignment','left',&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Units','normalized',&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Max',10,&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'BackgroundColor',[1&nbsp;1&nbsp;1],&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Position',[left+border&nbsp;bottom&nbsp;width-2*border&nbsp;height-0.05],&nbsp;...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Enable','inactive',...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'String','');</span><br>
<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Buttons&nbsp;===========================================================</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;--&nbsp;Export&nbsp;to&nbsp;EPS&nbsp;---------</span><br>
&nbsp;&nbsp;&nbsp;width=0.1;<br>
&nbsp;&nbsp;&nbsp;left=0.75-width;<br>
&nbsp;&nbsp;&nbsp;bottom=0.95;<br>
&nbsp;&nbsp;&nbsp;height=0.04;<br>
&nbsp;&nbsp;&nbsp;hbtclose&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'fig2eps(gcf)'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'FIG2EPS'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%----------------------------------</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Close&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;left=0.8;<br>
&nbsp;&nbsp;&nbsp;bottom=0.05;<br>
&nbsp;&nbsp;&nbsp;height=0.044;<br>
&nbsp;&nbsp;&nbsp;width=0.15;<br>
&nbsp;&nbsp;&nbsp;hbtclose&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'close(gcf)'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Close'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Info&nbsp;button:&nbsp;call&nbsp;stanard&nbsp;info&nbsp;box</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+1.5*height;<br>
&nbsp;&nbsp;&nbsp;hbtinfo&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'info'</span><span class=quotes>',gcf)'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Info'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Step&nbsp;button:&nbsp;perform&nbsp;one&nbsp;adaptation&nbsp;step</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+1.5*height;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hbtstep&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Step'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Interruptible'</span>,<span class=quotes>'off'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'step'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Stop&nbsp;button:&nbsp;stop&nbsp;process&nbsp;of&nbsp;adaptation</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+height;<br>
&nbsp;&nbsp;&nbsp;hbtstop&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Stop'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'set(gcbo,'</span><span class=quotes>'UserData'</span><span class=quotes>',1)'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Play&nbsp;button:&nbsp;begin&nbsp;adaptation</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+height;<br>
&nbsp;&nbsp;&nbsp;hbtplay&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Play'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'play'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Reset&nbsp;button:&nbsp;set&nbsp;up&nbsp;t&nbsp;=&nbsp;0</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+height;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hbtreset&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Reset'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'reset'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Create&nbsp;data</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+1.5*height;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hbtcreat&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Create&nbsp;data'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'creatdata'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Load&nbsp;data</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+1*height;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hbtload&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Load&nbsp;data'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'getfile'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Save&nbsp;model</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom+1.5*height;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hbtSaveModel&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'Normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Save&nbsp;model'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Callback'</span>,<span class=quotes>'demo_emgmm('</span><span class=quotes>'savemodel'</span><span class=quotes>',gcf)'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Load&nbsp;model</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;bottom=bottom+1*height;</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;hbtLoadModel&nbsp;=&nbsp;uicontrol(...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Units','Normalized',&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ListboxTop',0,&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Position',[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'String','Load&nbsp;model',&nbsp;...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Callback','demo_emgmm(''loadmodel'',gcf)');</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;PopUp&nbsp;Menu&nbsp;=====================================================</span><br>
&nbsp;&nbsp;&nbsp;bottom=0.95-height;<br>
&nbsp;&nbsp;&nbsp;htxfeatures=<span class=graph>uicontrol</span>(&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'text'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Covariance'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;popup&nbsp;menu</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom-height;<br>
&nbsp;&nbsp;&nbsp;hpufeatures=<span class=graph>uicontrol</span>(&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'popup'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,[<span class=quotes>'Diagonal&nbsp;'</span>;&nbsp;<span class=quotes>'Full&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'</span>]);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Edit&nbsp;line&nbsp;==========================================================</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;prior&nbsp;info&nbsp;about&nbsp;number&nbsp;of&nbsp;the&nbsp;classes</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom-1.3*height;<br>
&nbsp;&nbsp;&nbsp;htxclasses=<span class=graph>uicontrol</span>(&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'text'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;0.9*height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Components'</span>);<br>
&nbsp;&nbsp;&nbsp;bottom=bottom-height;<br>
&nbsp;&nbsp;&nbsp;hedclasses&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'edit'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'2'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Iterations</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom-1.3*height;<br>
&nbsp;&nbsp;&nbsp;htxiter=<span class=graph>uicontrol</span>(&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'text'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;0.9*height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Iterations'</span>);<br>
&nbsp;&nbsp;&nbsp;bottom=bottom-height;<br>
&nbsp;&nbsp;&nbsp;hediter&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'edit'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'1'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;CheckBox&nbsp;=========================================================</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Should&nbsp;the&nbsp;first&nbsp;algorithm&nbsp;step&nbsp;be&nbsp;random&nbsp;or&nbsp;not&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;bottom=bottom-height*1.3;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hxbrandom&nbsp;=&nbsp;<span class=graph>uicontrol</span>(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Style'</span>,<span class=quotes>'checkbox'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ListboxTop'</span>,0,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Position'</span>,[left&nbsp;bottom&nbsp;width&nbsp;height],&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'String'</span>,<span class=quotes>'Random&nbsp;init'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%=====================================================================</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Store&nbsp;handlers</span><br>
&nbsp;&nbsp;&nbsp;handlers=struct(...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'ellipse'</span>,struct(<span class=quotes>'handler'</span>,-1,<span class=quotes>'mi'</span>,[],<span class=quotes>'sigma'</span>,[],<span class=quotes>'t'</span>,0,<span class=quotes>'Pk'</span>,[],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'solution'</span>,0),...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'center'</span>,[],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'graph1'</span>,struct(<span class=quotes>'handler'</span>,-1,<span class=quotes>'loglik'</span>,[],<span class=quotes>'axist'</span>,0,<span class=quotes>'time'</span>,[]),...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'title1'</span>,htitle1,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'title2'</span>,htitle2,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btSaveModel'</span>,hbtSaveModel,...<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'btLoadModel',hbtLoadModel,...</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btstep'</span>,hbtstep,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btstop'</span>,hbtstop,...&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btclose'</span>,hbtclose,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btplay'</span>,hbtplay,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btreset'</span>,hbtreset,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btinfo'</span>,hbtinfo,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btload'</span>,hbtload,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'btcreat'</span>,hbtcreat,...&nbsp;<span class=comment>%%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'console',hconsole,...</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'txsteps'</span>,htxsteps,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'txclasses'</span>,htxclasses,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'txiter'</span>,htxiter,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'txfeatures'</span>,htxfeatures,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'pufeatures'</span>,hpufeatures,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'editer'</span>,hediter,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'xbrandom'</span>,hxbrandom,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'axes1'</span>,haxes1,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'axes2'</span>,haxes2,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'edclasses'</span>,hedclasses);<br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,handlers)<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Reset</span><br>
&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'reset'</span>,hfigure);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Put&nbsp;figure&nbsp;on&nbsp;desktop</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br>
&nbsp;&nbsp;&nbsp;drawnow;<br>
<br>
&nbsp;<span class=label>case</span>&nbsp;<span class=quotes>'savemodel'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Save&nbsp;model&nbsp;============================================</span><br>
<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t&nbsp;==&nbsp;0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errordlg(<span class=quotes>'No&nbsp;model&nbsp;has&nbsp;found&nbsp;yet.'</span>,<span class=quotes>'No&nbsp;model&nbsp;to&nbsp;save'</span>,<span class=quotes>'modal'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=jump>return</span>;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;[name,path]=uiputfile(<span class=quotes>'*.mat'</span>,<span class=quotes>'Save&nbsp;model'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;name&nbsp;~=&nbsp;0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mean&nbsp;=&nbsp;h.ellipse.mi;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cov&nbsp;=&nbsp;reshape(h.ellipse.sigma,2,2,size(Mean,2));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prior&nbsp;=&nbsp;h.ellipse.Pk;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fun&nbsp;=&nbsp;<span class=quotes>'pdfgmm'</span>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;save(strcat(path,name),<span class=quotes>'Mean'</span>,<span class=quotes>'Cov'</span>,<span class=quotes>'Prior'</span>,<span class=quotes>'fun'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;<span class=label>case</span>&nbsp;<span class=quotes>'loadmodel'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Load&nbsp;model&nbsp;============================================</span><br>
<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
&nbsp;&nbsp;&nbsp;sets=<span class=graph>get</span>(h.axes1,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Are&nbsp;data&nbsp;sets&nbsp;loaded&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;isempty(sets)==1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;no&nbsp;warning&nbsp;is&nbsp;needy&nbsp;because&nbsp;of&nbsp;the&nbsp;huge&nbsp;topic&nbsp;on&nbsp;the&nbsp;screen:))).</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=jump>return</span>;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;[name,path]=uigetfile(<span class=quotes>'*.mat'</span>,<span class=quotes>'Load&nbsp;model'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;name&nbsp;~=&nbsp;0,<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fname=strcat(path,name);<br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;checkdat(fname,DATA_IDENT,2,0)==1,</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'reset'</span>,hfigure);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model=load(fname);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;<span class=stack>exist</span>(<span class=quotes>'model.Pk'</span>)==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;suppose&nbsp;uniformly&nbsp;distributed&nbsp;Pk</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model.Pk=ones(1,sum(model.K))/sum(model.K);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.mi&nbsp;=&nbsp;model.MI;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.sigma=model.SIGMA;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.Pk&nbsp;=&nbsp;model.Pk;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.solution=0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t=0;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.edclasses,<span class=quotes>'String'</span>,num2str(sum(model.K)));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.classes=sum(model.K);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.features=<span class=graph>get</span>(h.pufeatures,<span class=quotes>'Value'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,h);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'step'</span>,hfigure);<br>
&nbsp;<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;else</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errordlg('This&nbsp;file&nbsp;does&nbsp;not&nbsp;contain&nbsp;required&nbsp;data.','Bad&nbsp;file','modal');</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;<span class=label>case</span>&nbsp;<span class=quotes>'play'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Play&nbsp;============================================</span><br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;data&nbsp;set</span><br>
&nbsp;&nbsp;&nbsp;sets=<span class=graph>get</span>(h.axes1,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Are&nbsp;data&nbsp;sets&nbsp;loaded&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;isempty(sets)==1&nbsp;|&nbsp;h.ellipse.solution==1,<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=sprintf(...</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'No&nbsp;action&nbsp;performed.&nbsp;No&nbsp;data&nbsp;to&nbsp;work&nbsp;on.&nbsp;Load&nbsp;or&nbsp;create&nbsp;it!');</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set(h.console,'String',text);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=jump>return</span>;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;disable&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>([h.editer,h.btstep,h.btclose,h.btplay,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.btreset,h.btinfo,h.btload,h.btcreat,h.txiter],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;enable&nbsp;stop&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.btstop,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;#&nbsp;of&nbsp;iterations</span><br>
&nbsp;&nbsp;&nbsp;iter=str2num(<span class=graph>get</span>(h.editer,<span class=quotes>'String'</span>));<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;#&nbsp;of&nbsp;classes</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.classes=str2num(<span class=graph>get</span>(h.edclasses,<span class=quotes>'String'</span>));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.features=<span class=graph>get</span>(h.pufeatures,<span class=quotes>'Value'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>([h.xbrandom,h.edclasses,h.txclasses,h.pufeatures,h.txfeatures],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Shall&nbsp;the&nbsp;init&nbsp;be&nbsp;random,&nbsp;yes&nbsp;or&nbsp;no&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;randinit=<span class=graph>get</span>(h.xbrandom,<span class=quotes>'Value'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;set&nbsp;stop&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.btstop,<span class=quotes>'UserData'</span>,0);<br>
<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Play&nbsp;-&nbsp;adaptation&nbsp;process</span><br>
&nbsp;&nbsp;&nbsp;play=1;&nbsp;<span class=comment>%&nbsp;flag&nbsp;1&nbsp;-&nbsp;not&nbsp;finished,&nbsp;1&nbsp;-&nbsp;finished;</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>while</span>&nbsp;play==1&nbsp;&&nbsp;<span class=graph>get</span>(h.btstop,<span class=quotes>'UserData'</span>)==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.rand&nbsp;=&nbsp;randinit;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>switch</span>&nbsp;3-h.ellipse.features,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=label>case</span>&nbsp;1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;<span class=quotes>'full'</span>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=label>case</span>&nbsp;2,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;<span class=quotes>'diag'</span>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;3-h.ellipse.features;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.ncomp=h.ellipse.classes;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.tmax&nbsp;=&nbsp;iter+h.ellipse.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t&nbsp;&gt;=&nbsp;1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.logL&nbsp;=&nbsp;h.ellipse.logL;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Alpha&nbsp;=&nbsp;h.ellipse.Alpha;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.t&nbsp;=&nbsp;h.ellipse.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Mean&nbsp;=&nbsp;h.ellipse.mi;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Cov&nbsp;=&nbsp;reshape(h.ellipse.sigma,2,2,size(h.ellipse.mi,2));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Prior&nbsp;=&nbsp;h.ellipse.Pk;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model=emgmm(sets.X,options,init_model);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model=emgmm(sets.X,options);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.mi&nbsp;=&nbsp;model.Mean;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.sigma&nbsp;=&nbsp;reshape(&nbsp;model.Cov,2,2*size(model.Mean,2));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.Pk&nbsp;=&nbsp;model.Prior;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[tmp,eI]=max(model.Alpha);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.solution&nbsp;=&nbsp;model.exitflag;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t&nbsp;=&nbsp;model.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.Alpha&nbsp;=&nbsp;model.Alpha;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.logL&nbsp;=&nbsp;model.logL(<span class=keyword>end</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;perform&nbsp;one&nbsp;learning&nbsp;step</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;h.ellipse.features==2,&nbsp;&nbsp;&nbsp;%&nbsp;correlated&nbsp;features</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk,eI,h.ellipse.solution,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t]=unsund(sets.X,h.ellipse.classes,iter,randinit,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t,h.ellipse.mi,&nbsp;h.ellipse.sigma,h.ellipse.Pk);</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;%&nbsp;independent</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk,eI,h.ellipse.solution,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t]=unsuni(sets.X,h.ellipse.classes,iter,randinit,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t,h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk);</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'step&nbsp;number&nbsp;t=%d&nbsp;'</span>,h.ellipse.t);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.solution==1,<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=strvcat(text,'EM&nbsp;has&nbsp;converged.');</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=[text&nbsp;<span class=quotes>',EM&nbsp;has&nbsp;converged.'</span>];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;play=0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val=&nbsp;mln(sets.X,h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'Log-likelihood,&nbsp;logL(t)&nbsp;=&nbsp;%f'</span>,val);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.title2,<span class=quotes>'String'</span>,text);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.time=[h.graph1.time,h.ellipse.t];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.loglik=[h.graph1.loglik,val];<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ylimit=<span class=graph>get</span>(h.axes2,<span class=quotes>'YLim'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;ylimit(2)&nbsp;&lt;&nbsp;val,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.axes2,<span class=quotes>'YLim'</span>,[ylimit(1)&nbsp;val+AXISY_ADD]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;is&nbsp;axis&nbsp;to&nbsp;be&nbsp;changed&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t&nbsp;&gt;&nbsp;h.graph1.axist,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.axist=h.ellipse.t+iter*AXIST_ADD;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.axes2,<span class=quotes>'XLim'</span>,[1&nbsp;h.graph1.axist]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.graph1.handler,<span class=quotes>'XData'</span>,h.graph1.time,<span class=quotes>'YData'</span>,h.graph1.loglik,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.handler==-1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>axes</span>(h.axes1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.handler,h.center]=...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pnmix(sets.X,h.ellipse.mi,h.ellipse.sigma,eI,h.ellipse.handler,h.center);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;comment</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set(h.console,'String',text);</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;store&nbsp;data</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,h);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;flush&nbsp;it&nbsp;on&nbsp;desktop</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drawnow;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;<span class=comment>%&nbsp;of&nbsp;while</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;dissable&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>([h.editer,h.btstep,h.btclose,h.btplay,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.btreset,h.btinfo,h.btload,h.btcreat,h.txiter],...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;enable&nbsp;stop&nbsp;button</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.btstop,<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;copy&nbsp;the&nbsp;solution&nbsp;to&nbsp;global&nbsp;variables&nbsp;to&nbsp;be&nbsp;visible&nbsp;outside&nbsp;demo_emgmm</span><br>
&nbsp;&nbsp;&nbsp;UNSU_MI&nbsp;=&nbsp;h.ellipse.mi;<br>
&nbsp;&nbsp;&nbsp;UNSU_SIGMA&nbsp;=&nbsp;h.ellipse.sigma;<br>
&nbsp;&nbsp;&nbsp;UNSU_PK&nbsp;=&nbsp;h.ellipse.Pk;<br>
&nbsp;&nbsp;&nbsp;UNSU_solution&nbsp;=&nbsp;h.ellipse.solution;<br>
&nbsp;&nbsp;&nbsp;UNSU_t&nbsp;=&nbsp;h.ellipse.t;<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'step'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;One&nbsp;step&nbsp;of&nbsp;learning&nbsp;===========================================</span><br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;data&nbsp;set</span><br>
&nbsp;&nbsp;&nbsp;sets=<span class=graph>get</span>(h.axes1,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;are&nbsp;data&nbsp;sets&nbsp;loaded&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;isempty(sets)==1&nbsp;|&nbsp;h.ellipse.solution==1,<br>
<span class=comment>%%text=sprintf('No&nbsp;action&nbsp;performed.&nbsp;No&nbsp;data&nbsp;to&nbsp;work&nbsp;on.&nbsp;Load&nbsp;or&nbsp;create&nbsp;it!');</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set(h.console,'String',text);</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set(h.txsteps,'String',text);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=jump>return</span>;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;#&nbsp;of&nbsp;iter</span><br>
&nbsp;&nbsp;&nbsp;iter=str2num(<span class=graph>get</span>(h.editer,<span class=quotes>'String'</span>));<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;#&nbsp;of&nbsp;classes</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.classes=str2num(<span class=graph>get</span>(h.edclasses,<span class=quotes>'String'</span>));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.features=<span class=graph>get</span>(h.pufeatures,<span class=quotes>'Value'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>([h.xbrandom,h.edclasses,h.txclasses,h.pufeatures,h.txfeatures],<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;random&nbsp;init&nbsp;yes&nbsp;or&nbsp;no</span><br>
&nbsp;&nbsp;&nbsp;randinit=<span class=graph>get</span>(h.xbrandom,<span class=quotes>'Value'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;perform&nbsp;one&nbsp;learning&nbsp;step</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;if&nbsp;h.ellipse.features==2,&nbsp;&nbsp;&nbsp;%&nbsp;correlated</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk,eI,h.ellipse.solution,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t]=unsund(sets.X,h.ellipse.classes,iter,randinit,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t,h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk);</span><br>
<span class=comment>%&nbsp;&nbsp;else&nbsp;%&nbsp;independent</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.rand&nbsp;=&nbsp;randinit;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>switch</span>&nbsp;3-h.ellipse.features,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=label>case</span>&nbsp;1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;<span class=quotes>'full'</span>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=label>case</span>&nbsp;2,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;<span class=quotes>'diag'</span>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.cov_type&nbsp;=&nbsp;3-h.ellipse.features;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.ncomp=h.ellipse.classes;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.tmax&nbsp;=&nbsp;iter+h.ellipse.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t&nbsp;&gt;=&nbsp;1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.logL&nbsp;=&nbsp;h.ellipse.logL;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Alpha&nbsp;=&nbsp;h.ellipse.Alpha;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.t&nbsp;=&nbsp;h.ellipse.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Mean&nbsp;=&nbsp;h.ellipse.mi;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Cov&nbsp;=&nbsp;reshape(h.ellipse.sigma,2,2,size(h.ellipse.mi,2));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init_model.Prior&nbsp;=&nbsp;h.ellipse.Pk;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model=emgmm(sets.X,options,init_model);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model=emgmm(sets.X,options);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.mi&nbsp;=&nbsp;model.Mean;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.sigma&nbsp;=&nbsp;reshape(&nbsp;model.Cov,2,2*size(model.Mean,2));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.Pk&nbsp;=&nbsp;model.Prior;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[tmp,eI]=max(model.Alpha);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.solution&nbsp;=&nbsp;model.exitflag;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t&nbsp;=&nbsp;model.t;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.Alpha&nbsp;=&nbsp;model.Alpha;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.logL&nbsp;=&nbsp;model.logL(<span class=keyword>end</span>);<br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk,eI,h.ellipse.solution,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t]=unsuni(sets.X,h.ellipse.classes,iter,randinit,...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.ellipse.t,h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk);</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;h.ellipse</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;end</span><br>
<br>
&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'step&nbsp;number&nbsp;t=%d&nbsp;'</span>,h.ellipse.t);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.solution==1,<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=strvcat(text,'Solution&nbsp;is&nbsp;found.');</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=[text&nbsp;<span class=quotes>',EM&nbsp;has&nbsp;converged.'</span>];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val=&nbsp;mln(sets.X,h.ellipse.mi,h.ellipse.sigma,h.ellipse.Pk);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'Log-likelihood,&nbsp;logL(t)&nbsp;=&nbsp;%f'</span>,val);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.title2,<span class=quotes>'String'</span>,text);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.time=[h.graph1.time,h.ellipse.t];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.loglik=[h.graph1.loglik,val];<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ylimit=<span class=graph>get</span>(h.axes2,<span class=quotes>'YLim'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;ylimit(2)&nbsp;&lt;&nbsp;val,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.axes2,<span class=quotes>'YLim'</span>,[ylimit(1)&nbsp;val+AXISY_ADD]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;is&nbsp;axis&nbsp;to&nbsp;be&nbsp;changed&nbsp;?</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.t&nbsp;&gt;&nbsp;h.graph1.axist,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.graph1.axist=h.ellipse.t+iter*AXIST_ADD;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.axes2,<span class=quotes>'XLim'</span>,[1&nbsp;h.graph1.axist]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.graph1.handler,<span class=quotes>'XData'</span>,h.graph1.time,<span class=quotes>'YData'</span>,h.graph1.loglik,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;h.ellipse.handler==-1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>axes</span>(h.axes1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[h.ellipse.handler,h.center]=...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pnmix(sets.X,h.ellipse.mi,h.ellipse.sigma,eI,h.ellipse.handler,h.center);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;comment</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;set(h.console,'String',text);</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;flush&nbsp;it&nbsp;on&nbsp;desktop</span><br>
&nbsp;&nbsp;&nbsp;drawnow;<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,h);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;copy&nbsp;the&nbsp;solution&nbsp;to&nbsp;global&nbsp;variables&nbsp;to&nbsp;be&nbsp;visible&nbsp;outside&nbsp;demo_emgmm</span><br>
&nbsp;&nbsp;&nbsp;UNSU_MI&nbsp;=&nbsp;h.ellipse.mi;<br>
&nbsp;&nbsp;&nbsp;UNSU_SIGMA&nbsp;=&nbsp;h.ellipse.sigma;<br>
&nbsp;&nbsp;&nbsp;UNSU_PK&nbsp;=&nbsp;h.ellipse.Pk;<br>
&nbsp;&nbsp;&nbsp;UNSU_solution&nbsp;=&nbsp;h.ellipse.solution;<br>
&nbsp;&nbsp;&nbsp;UNSU_t&nbsp;=&nbsp;h.ellipse.t;<br>
<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'getfile'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Invoke&nbsp;standard&nbsp;open&nbsp;file&nbsp;dialog&nbsp;====================================</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Opens&nbsp;file&nbsp;and&nbsp;checks&nbsp;if&nbsp;contains&nbsp;apropriate&nbsp;data,&nbsp;if&nbsp;yes&nbsp;than&nbsp;loads&nbsp;data.</span><br>
<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;change&nbsp;path&nbsp;to&nbsp;directory</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;wres=what('unsuper');</span><br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;cd(wres.path);</span><br>
<br>
&nbsp;&nbsp;&nbsp;[name,path]=uigetfile(<span class=quotes>'*.mat'</span>,<span class=quotes>'Open&nbsp;file'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;name~=0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.pathname=strcat(path,name);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.path=path;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.name=name;<br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;checkdat(file.pathname,DATA_IDENT,2,0)==1,</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;check2ddata(file.pathname)==1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.btload,<span class=quotes>'UserData'</span>,file);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'loadsets'</span>,hfigure);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errordlg(<span class=quotes>'This&nbsp;file&nbsp;does&nbsp;not&nbsp;contain&nbsp;required&nbsp;data.'</span>,<span class=quotes>'Bad&nbsp;file'</span>,<span class=quotes>'modal'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'loadsets'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Load&nbsp;sets&nbsp;==================================================================</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Get&nbsp;file&nbsp;name&nbsp;from&nbsp;the&nbsp;pop&nbsp;up&nbsp;menu&nbsp;according&nbsp;to&nbsp;menu&nbsp;pointer.</span><br>
<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Get&nbsp;file&nbsp;name&nbsp;with&nbsp;sets</span><br>
&nbsp;&nbsp;&nbsp;file=<span class=graph>get</span>(h.btload,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;Load&nbsp;sets</span><br>
&nbsp;&nbsp;&nbsp;sets=load(file.pathname);<br>
&nbsp;&nbsp;&nbsp;sets.K&nbsp;=&nbsp;size(sets.X,2);<br>
&nbsp;&nbsp;&nbsp;sets.N&nbsp;=&nbsp;size(sets.X,1);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;store&nbsp;loaded&nbsp;sets</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.axes1,<span class=quotes>'UserData'</span>,sets);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;call&nbsp;reset</span><br>
&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'reset'</span>,hfigure);<br>
<br>
&nbsp;&nbsp;&nbsp;drawnow;<br>
<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'reset'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Reset&nbsp;adaptation&nbsp;process,&nbsp;set&nbsp;up&nbsp;t=0&nbsp;================</span><br>
<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;handlers</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;file</span><br>
&nbsp;&nbsp;&nbsp;file=<span class=graph>get</span>(h.btload,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;data&nbsp;set</span><br>
&nbsp;&nbsp;&nbsp;sets=<span class=graph>get</span>(h.axes1,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;zeroes&nbsp;parameters&nbsp;of&nbsp;the&nbsp;separation&nbsp;line</span><br>
&nbsp;&nbsp;&nbsp;h.ellipse.mi=[];<br>
&nbsp;&nbsp;&nbsp;h.ellipse.sigma=[];<br>
&nbsp;&nbsp;&nbsp;h.ellipse.t=0;<br>
&nbsp;&nbsp;&nbsp;h.ellipse.Pk=[];<br>
&nbsp;&nbsp;&nbsp;h.center=-1;<br>
&nbsp;&nbsp;&nbsp;h.ellipse.handler=-1;<br>
&nbsp;&nbsp;&nbsp;h.ellipse.solution=0;<br>
<br>
&nbsp;&nbsp;&nbsp;h.graph1.time=[];<br>
&nbsp;&nbsp;&nbsp;h.graph1.axist=0;<br>
&nbsp;&nbsp;&nbsp;h.graph1.loglik=[];<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;clear&nbsp;axes&nbsp;prob.</span><br>
&nbsp;&nbsp;&nbsp;clrchild(h.axes2);<br>
&nbsp;&nbsp;&nbsp;<span class=graph>axes</span>(h.axes2);<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;setaxis(h.axes2,[0&nbsp;1&nbsp;0&nbsp;1]);</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>axis</span>&nbsp;auto;<br>
&nbsp;&nbsp;&nbsp;h.graph1.handler=<span class=graph>plot</span>([0],[0],<span class=quotes>'b'</span>,<span class=quotes>'Parent'</span>,h.axes2,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'EraseMode'</span>,<span class=quotes>'background'</span>,<span class=quotes>'Visible'</span>,<span class=quotes>'off'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;store&nbsp;h</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,h);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;enable&nbsp;Edit&nbsp;Line&nbsp;'classes'</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>([h.xbrandom,h.edclasses,h.txclasses,h.pufeatures,h.txfeatures],<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;comment</span><br>
&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'Log-likelihood,&nbsp;logL(t)'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.title2,<span class=quotes>'String'</span>,text);<br>
<br>
&nbsp;&nbsp;&nbsp;text=<span class=io>sprintf</span>(<span class=quotes>'step&nbsp;number&nbsp;t=0.&nbsp;'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;clears&nbsp;axes</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(<span class=graph>get</span>(h.axes1,<span class=quotes>'Children'</span>),<span class=quotes>'EraseMode'</span>,<span class=quotes>'normal'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%%%&nbsp;&nbsp;&nbsp;cla;</span><br>
&nbsp;&nbsp;&nbsp;clrchild(h.axes1);<br>
&nbsp;&nbsp;&nbsp;drawnow;<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;set&nbsp;axes&nbsp;and&nbsp;plot&nbsp;mixture</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>axes</span>(h.axes1);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;isempty(sets)==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;win=cmpwin(min(sets.X<span class=quotes>'),max(sets.X'</span>),BORDER,BORDER);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;axis(win);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setaxis(h.axes1,win);<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;axes(h.axes1);</span><br>
<br>
<span class=comment>%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ppoints(sets.X,sets.I);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ppatterns(sets.X);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span><br>
<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;create&nbsp;comment</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;isempty(sets)==0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.title1,<span class=quotes>'String'</span>,<span class=io>sprintf</span>(<span class=quotes>'File:&nbsp;%s,&nbsp;#&nbsp;of&nbsp;points&nbsp;K&nbsp;=&nbsp;%d'</span>,file.name,sum(sets.K)));<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.title1,<span class=quotes>'String'</span>,<span class=quotes>'No&nbsp;data&nbsp;loaded'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos=<span class=graph>get</span>(h.axes1,<span class=quotes>'Position'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fsize=min(pos(3),pos(4))/7;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setaxis(h.axes1,[-1&nbsp;1&nbsp;-1&nbsp;1]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=eval>builtin</span>(<span class=quotes>'text'</span>,0,0,<span class=quotes>'Press&nbsp;'</span><span class=quotes>'Load&nbsp;data'</span><span class=quotes>'&nbsp;button.'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Parent'</span>,h.axes1,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'HorizontalAlignment'</span>,<span class=quotes>'center'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'FontUnits'</span>,<span class=quotes>'normalized'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Clipping'</span>,<span class=quotes>'on'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'FontSize'</span>,fsize);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=eval>builtin</span>(<span class=quotes>'text'</span>,0,-fsize*2,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Load&nbsp;sample&nbsp;data&nbsp;from&nbsp;../toolboxroot/data/gmm\_samples/&nbsp;'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Parent'</span>,h.axes1,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'HorizontalAlignment'</span>,<span class=quotes>'center'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'FontUnits'</span>,<span class=quotes>'normalized'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'Clipping'</span>,<span class=quotes>'on'</span>,...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=quotes>'FontSize'</span>,fsize*0.65);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
&nbsp;&nbsp;&nbsp;drawnow;<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'creatdata'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Invoke&nbsp;data&nbsp;set&nbsp;creator&nbsp;============================================</span><br>
&nbsp;&nbsp;&nbsp;createdata(<span class=quotes>'finite'</span>,10,<span class=quotes>'demo_emgmm'</span>,<span class=quotes>'created'</span>,hfigure);<br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'created'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Load&nbsp;new&nbsp;created&nbsp;data&nbsp;set&nbsp;===========================================</span><br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;handler&nbsp;and&nbsp;make&nbsp;this&nbsp;figure&nbsp;active</span><br>
&nbsp;&nbsp;&nbsp;<span class=graph>figure</span>(hfigure);<br>
&nbsp;&nbsp;&nbsp;h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;get&nbsp;file&nbsp;name</span><br>
&nbsp;&nbsp;&nbsp;path=<span class=stack>varargin</span>{1};<br>
&nbsp;&nbsp;&nbsp;name=<span class=stack>varargin</span>{2};<br>
&nbsp;&nbsp;&nbsp;pathname=strcat(path,name);<br>
<br>
<span class=comment>%&nbsp;&nbsp;&nbsp;if&nbsp;checkdat(pathname,DATA_IDENT,2,0)==1,</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;check2ddata(pathname)==1,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.pathname=pathname;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.path=path;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.name=name;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(h.btload,<span class=quotes>'UserData'</span>,file);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo_emgmm(<span class=quotes>'loadsets'</span>,hfigure);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errordlg(<span class=quotes>'This&nbsp;file&nbsp;does&nbsp;not&nbsp;contain&nbsp;required&nbsp;data.'</span>,<span class=quotes>'Bad&nbsp;file'</span>,<span class=quotes>'modal'</span>);<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<br>
<span class=label>case</span>&nbsp;<span class=quotes>'info'</span><br>
&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;==&nbsp;Call&nbsp;standard&nbsp;Matlab`s&nbsp;info&nbsp;box&nbsp;=========================================</span><br>
&nbsp;&nbsp;&nbsp;helpwin(mfilename);<br>
<br>
<span class=keyword>end</span>&nbsp;<span class=comment>%&nbsp;of&nbsp;switch</span><br>
<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[]</span>=<span class=defun_name>clrchild</span>(<span class=defun_in>handle</span>)<br>
delete(<span class=graph>get</span>(handle,<span class=quotes>'Children'</span>));<br>
<span class=jump>return</span>;<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[]</span>=<span class=defun_name>setaxis</span>(<span class=defun_in>handle,rect</span>)<br>
<span class=graph>set</span>(handle,<span class=quotes>'XLim'</span>,rect(1:2));<br>
<span class=graph>set</span>(handle,<span class=quotes>'YLim'</span>,rect(3:4));<br>
<br>
<span class=keyword>if</span>&nbsp;size(rect,2)&gt;=6,<br>
&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(handle,<span class=quotes>'ZLim'</span>,rect(5:6));<br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[win]</span>=<span class=defun_name>cmpwin</span>(<span class=defun_in>mins,maxs,xborder,yborder</span>)<br>
dx=max(&nbsp;(maxs(1)-mins(1)),&nbsp;1&nbsp;)*xborder;<br>
dy=max(&nbsp;(maxs(2)-mins(2)),&nbsp;1&nbsp;)*yborder;<br>
<br>
x1=(mins(1)-dx);<br>
x2=(maxs(1)+dx);<br>
y1=(mins(2)-dy);<br>
y2=(maxs(2)+dx);<br>
<br>
win=[x1&nbsp;x2&nbsp;y1&nbsp;y2];<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[logL]&nbsp;</span>=&nbsp;<span class=defun_name>mln</span>(<span class=defun_in>X,MI,SIGMA,Pk</span>)<br>
&nbsp;<br>
<br>
D=size(MI,1);&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;dimension</span><br>
K=size(MI,2);&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;%&nbsp;of&nbsp;classes</span><br>
N=size(X,2);&nbsp;&nbsp;&nbsp;&nbsp;<span class=comment>%&nbsp;#&nbsp;of&nbsp;points</span><br>
<br>
A=zeros(N,K);<br>
<br>
<span class=keyword>for</span>&nbsp;k=1:K,<br>
&nbsp;&nbsp;&nbsp;&nbsp;pxk=normald(X,MI(:,k),SIGMA(:,1+(k-1)*D:k*D));<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;A(:,k)=pxk(:)*Pk(k);<br>
<span class=keyword>end</span><br>
<br>
logL=sum(log(sum(A,2)));<br>
<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[p]</span>=<span class=defun_name>normald</span>(<span class=defun_in>X,mi,sigma</span>)<br>
<br>
DIM=size(X,1);<br>
p=exp(-1/2*mahalan(X,mi,sigma))/((2*pi)^(DIM/2)&nbsp;*&nbsp;sqrt(det(sigma)));<br>
<br>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>[hellipse,hcenter]</span>=<span class=defun_name>pnmix</span>(<span class=defun_in>X,MI,SIGMA,I,hellipse,hcenter</span>)<br>
<span class=comment>%&nbsp;&nbsp;[hellipse,hcenter]=pnmix(X,MI,SIGMA,I,hellipse,hcenter)</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;PNMIX&nbsp;vizualizes&nbsp;mixture&nbsp;of&nbsp;normal&nbsp;distributions&nbsp;in&nbsp;2D&nbsp;space.&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;Each&nbsp;normal&nbsp;distribution&nbsp;is&nbsp;determined&nbsp;by&nbsp;a&nbsp;pair&nbsp;of&nbsp;mean&nbsp;values&nbsp;and&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;covariance&nbsp;matrix.&nbsp;The&nbsp;mean&nbsp;value&nbsp;is&nbsp;vizualized&nbsp;as&nbsp;a&nbsp;point&nbsp;and&nbsp;the&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;covariance&nbsp;matrix&nbsp;as&nbsp;en&nbsp;ellipse.&nbsp;A&nbsp;size&nbsp;of&nbsp;the&nbsp;ellipse&nbsp;is&nbsp;determined&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;in&nbsp;order&nbsp;to&nbsp;contain&nbsp;all&nbsp;the&nbsp;points&nbsp;belonging&nbsp;to&nbsp;given&nbsp;class&nbsp;which&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;the&nbsp;ellipse&nbsp;describes.</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;&nbsp;Input&nbsp;and&nbsp;output&nbsp;arguments&nbsp;hellipse&nbsp;and&nbsp;hcenter&nbsp;contain</span><br>
<span class=comment>%&nbsp;&nbsp;handles&nbsp;of&nbsp;graphics&nbsp;objects&nbsp;(ellipses&nbsp;and&nbsp;their&nbsp;centers)&nbsp;and</span><br>
<span class=comment>%&nbsp;&nbsp;if&nbsp;they&nbsp;enter&nbsp;the&nbsp;function,&nbsp;the&nbsp;old&nbsp;graphics&nbsp;objects&nbsp;vanish&nbsp;and&nbsp;</span><br>
<span class=comment>%&nbsp;&nbsp;then&nbsp;new&nbsp;objects&nbsp;are&nbsp;plotted.</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;&nbsp;The&nbsp;function&nbsp;is&nbsp;useful&nbsp;for&nbsp;vizualization&nbsp;of&nbsp;results&nbsp;of&nbsp;the&nbsp;unsupervised</span><br>
<span class=comment>%&nbsp;&nbsp;learning&nbsp;algorithms&nbsp;(see&nbsp;help&nbsp;of&nbsp;UNSUNI,&nbsp;UNSUND).</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;Input:</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;X&nbsp;[NxK]&nbsp;contains&nbsp;K&nbsp;points&nbsp;which&nbsp;are&nbsp;N-dimensional,&nbsp;X=[x_1,x_2,...,x_K].</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;I&nbsp;[1xK]&nbsp;contains&nbsp;class&nbsp;labels&nbsp;for&nbsp;all&nbsp;the&nbsp;points.</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;MI&nbsp;[NxM]&nbsp;mean&nbsp;values&nbsp;for&nbsp;each&nbsp;class,&nbsp;MI=[mi_1,mi_2,...,mi_M]</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;SIGMA&nbsp;[Nx(MxN)]&nbsp;covariance&nbsp;matrices&nbsp;for&nbsp;each&nbsp;class,</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SIGMA=[sigma_1,sigma_2,...,sigma_M].</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;hellipse&nbsp;[vector],&nbsp;hcenter&nbsp;[vector]&nbsp;handlers&nbsp;of&nbsp;graphics&nbsp;objects.</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;Output:</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;hellipse&nbsp;[vector],&nbsp;hcenter&nbsp;[vector]&nbsp;handlers&nbsp;of&nbsp;graphics&nbsp;objects.</span><br>
<span class=comment>%</span><br>
<span class=comment>%&nbsp;See&nbsp;also&nbsp;UNSUNI,&nbsp;UNSUND,&nbsp;UNSUDEMO.</span><br>
<span class=comment>%</span><br>
<br>
<br>
<span class=comment>%&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox,&nbsp;Vojtech&nbsp;Franc,&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=comment>%&nbsp;(c)&nbsp;Czech&nbsp;Technical&nbsp;University&nbsp;Prague,&nbsp;http://cmp.felk.cvut.cz</span><br>
<span class=comment>%&nbsp;Written&nbsp;Vojtech&nbsp;Franc&nbsp;(diploma&nbsp;thesis)&nbsp;10.11.1999,&nbsp;23.12.1999</span><br>
<span class=comment>%&nbsp;Modifications:</span><br>
<span class=comment>%&nbsp;22.&nbsp;6.00&nbsp;V.&nbsp;Hlavac,&nbsp;comments&nbsp;polished.</span><br>
<br>
<br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;5,<br>
&nbsp;&nbsp;hellipse=-1;<br>
<span class=keyword>end</span><br>
<br>
DIM=size(X,1);<br>
N=size(X,2);<br>
K=size(MI,2);<br>
maxr=zeros(1,K);<br>
<span class=keyword>for</span>&nbsp;i=1:N,<br>
&nbsp;&nbsp;&nbsp;r=sqrt(mahalan(X(:,i),MI(:,I(i)),SIGMA(:,(I(i)-1)*DIM+1:DIM*I(i))));<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;maxr(I(i))&nbsp;&lt;&nbsp;r,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxr(I(i))&nbsp;=&nbsp;r;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>end</span><br>
<br>
<span class=keyword>if</span>&nbsp;hellipse==-1,<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>for</span>&nbsp;i=1:K,<br>
<span class=comment>%%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[x,y]=ellipse(inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),30,maxr(i),MI(:,i));</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[x,y]=ellips(MI(:,i),inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),maxr(i),30);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hellipse(i)=<span class=graph>plot</span>(x,y,<span class=quotes>'k'</span>,<span class=quotes>'EraseMode'</span>,<span class=quotes>'xor'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hcenter(i)=<span class=graph>plot</span>(MI(1,i),MI(2,i),<span class=quotes>'+k'</span>,<span class=quotes>'EraseMode'</span>,<span class=quotes>'xor'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drawnow;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;<span class=keyword>for</span>&nbsp;i=1:K,<br>
<span class=comment>%%%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[x,y]=ellipse(inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),30,maxr(i),MI(:,i));</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[x,y]=ellips(MI(:,i),inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),maxr(i),30);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hellipse(i),<span class=quotes>'XData'</span>,x,<span class=quotes>'YData'</span>,y,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=graph>set</span>(hcenter(i),<span class=quotes>'XData'</span>,MI(1,i),<span class=quotes>'YData'</span>,MI(2,i),<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drawnow;<br>
&nbsp;&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>end</span><br>
</code>
